home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_6.zip / WINDOW.C < prev    next >
C/C++ Source or Header  |  1993-08-05  |  6KB  |  215 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include "externs.h"
  21.  
  22. typedef char AVL_WIN[AVL_MAX_WINDOWS][61];
  23.  
  24. void AVL_SHOW_WIN(AVL_WIN w, int r)
  25. {
  26.     int i;    
  27.     short co;
  28.     for(i = 1; i <= r; ++i)  {
  29.         _settextposition(i,1);
  30.         if ((i - 1) == avl_window)
  31.             co = _settextcolor(avl_men_ready);
  32.         else
  33.             co = _settextcolor(avl_men_letter);
  34.         _outtext(w[i - 1]);
  35.         }
  36.     _settextcolor(co);
  37. }
  38.  
  39.  
  40.                 
  41. void AVL_WINDOW()
  42. {
  43.         int x ;
  44.         int no = 0;
  45.         int ch, cols = 0, rows = 0;
  46.         AVL_WIN win;
  47.         AVL_WIN_PTR hw, hw2;
  48.         AVL_EDIT_WINDOW_PTR w;
  49.         if (avl_nwindows == 1)  {
  50.             AVL_ERROR("Use this option when working with more than one text file.");
  51.             return;
  52.             }
  53.         rows = avl_nwindows;
  54.         for(x = 0; x < avl_nwindows; ++x)  {
  55.             if ((no = strlen(avl_windows[x].file_name)) > cols)
  56.                 cols = no;
  57.                 sprintf(win[x],"%d %s", x + 1,avl_windows[x].file_name);
  58.                 }
  59.         hw2 = AVL_MAKE_WINDOW("",13,55,13+9,55+24,avl_wnd_bk_color,avl_wnd_color);
  60.         _outtext(" Use the arrow keys to\n");
  61.         _outtext(" go  over  the  units.\n");
  62.         _outtext("\n");
  63.         _outtext(" Press  <enter>  to\n");
  64.         _outtext(" select  an  unit  or\n");
  65.         _outtext(" type  the  unit's no.\n");
  66.         _outtext("\n");
  67.         _outtext(" Press ESC to  cancel.");
  68.         hw = AVL_MAKE_WINDOW("",3,avl_menu[5].c,3+rows+1,avl_menu[5].c+cols+4,avl_wnd_bk_color,avl_wnd_color);
  69.         while ( 1 )  {
  70.             AVL_SHOW_WIN(win,rows);
  71.             ch = getch();
  72.             if ((ch >= '1' && ch <= (rows + '0')) || (ch == 13)) {
  73.                 if (ch != 13)
  74.                     avl_window = ch - '0' - 1;
  75.                 AVL_DEL_WINDOW(hw);
  76.                 AVL_DEL_WINDOW(hw2);
  77.                 return;
  78.                 }
  79.             else {
  80.                 if (ch == 0 || ch == 0xE0) {
  81.                     ch = getch();
  82.                     switch( ch ) {
  83.                         case 72 : /* Up   */ 
  84.                             if (--avl_window < 0) 
  85.                                 avl_window = avl_nwindows - 1;
  86.                             break;
  87.                         case 80 : /* Down */ 
  88.                             if (++avl_window >= avl_nwindows)
  89.                                 avl_window = 0;
  90.                             break;
  91.                         default : putchar(7); break;
  92.                         }
  93.                     continue;
  94.                     }
  95.                 if (ch == 27)  {
  96.                     AVL_DEL_WINDOW(hw);
  97.                     AVL_DEL_WINDOW(hw2);
  98.                     return;
  99.                     }
  100.                 putch(7);
  101.                 continue;
  102.                 }
  103.             }
  104. }            
  105.  
  106.     
  107.  
  108. char *AVL_BORDER(char *s, short r1, short c1, short r2, short c2,short bk, short co)
  109. {
  110. /*    static char *avl_border = "┌┐└┘─│├┤";  */
  111.     char avl_border[8];
  112.     int i, j, n;
  113.     short color;
  114.     char buf[81];
  115.     char format[10];
  116.     avl_no_up_corner = 0;
  117.     if (avl_no_up_corner)  {
  118.         avl_border[0] = 203;
  119.         avl_border[1] = 203;
  120.         }
  121.     else {
  122.         avl_border[0] = 201;
  123.         avl_border[1] = 187;
  124.         }
  125.     avl_border[2] = 200;
  126.     avl_border[3] = 188;
  127.     avl_border[4] = 205;
  128.     avl_border[5] = 186;
  129.     sprintf(format,"%c-%ds",'%',c2-c1);
  130.     _settextwindow(r1,c1,r2,c2);
  131.     _setbkcolor( bk );
  132.     _settextcolor( co );
  133.     _settextposition(r2-r1+1,c2-c1+1);
  134.     _outmem(avl_border+3,1);
  135.     _scrolltextwindow( -1 );
  136.     sprintf(buf,format," ");
  137.     for(i = 2; i < (r2 - r1 + 1); ++i) {
  138.         _settextposition(i, 1 );
  139.         _outtext(buf);
  140.         }
  141.     for(i = 0; i < 78; ++i)
  142.         buf[i] = *(avl_border+4);
  143.     buf[c2-c1-1] = '\0';
  144.     _settextposition(1 , 2 );
  145.     _outtext(buf);
  146.     _settextposition(r2 - r1 +1, 2 );
  147.     _outtext(buf);
  148.     for(i = 2; i < (r2 - r1 + 1); ++i) {
  149.         _settextposition(i, 1 );
  150.         _outmem(avl_border+5,1);
  151.         _settextposition(i, c2 - c1 + 1);
  152.         _outmem(avl_border+5,1);
  153.         }
  154.     _settextposition(1,1);
  155.     _outmem(avl_border,1);
  156.     _settextposition(1,c2-c1+1);
  157.     _outmem(avl_border+1,1);
  158.     _settextposition(r2-r1+1,1);
  159.     _outmem(avl_border+2,1);
  160.     color = _settextcolor( avl_wnd_title );
  161.     n = (c2 - c1 + 1 - strlen(s)) / 2;
  162.     _settextposition(1,n);
  163.     _outtext(s);
  164.     color = _settextcolor( color );
  165.     _settextwindow(r1+1,c1+1,r2-1,c2-1);
  166.     _settextposition(1,1);
  167. }
  168.  
  169.  
  170. AVL_WIN_PTR AVL_MAKE_WINDOW(char *s, short r1,short c1,short r2,short c2,short bk, short co)
  171. {
  172.     AVL_WIN_PTR temp;
  173.     temp = calloc(1,sizeof(AVL_WIN_SIZE));
  174.     if (temp == NULL)  {
  175.         AVL_ERROR("Out of memory!");
  176.         exit(1);
  177.         }
  178.     temp -> bk = _getbkcolor();
  179.     temp -> co = _gettextcolor();
  180.     memmove(temp -> video, 0xb8000, 4000);
  181.     _gettextwindow(&temp -> r1,&temp -> c1,&temp -> r2,&temp -> c2);
  182.     temp -> pos = _gettextposition();
  183.     AVL_BORDER(s,r1,c1,r2,c2,bk,co);
  184.     _setbkcolor(bk);
  185.     _settextcolor(co);
  186.     return temp;
  187. }
  188.  
  189. void AVL_DEL_WINDOW(AVL_WIN_PTR w)
  190. {
  191.     struct rccoord pos;
  192.     short *s, *d;
  193.     char *p;
  194.     unsigned char c, att;
  195.     short i, j;
  196.     if (w != NULL)  {
  197. /*        memmove(0xb8000, w -> video, 4000);   */
  198.         d = (short *) 0xb8000;
  199.         p =  w -> video;
  200.         s = (short *) p;
  201.         for(i = 0; i < 2000; ++i) {
  202.             c = *s;
  203.             att = *s >> 8;        
  204.             AVL_WVIDEO(c,att,d);
  205.             ++s;
  206.             ++d;
  207.             }
  208.         _settextwindow(w -> r1,w -> c1,w -> r2,w -> c2);
  209.         _setbkcolor(w -> bk);
  210.         _settextcolor(w -> co);
  211.         pos = _settextposition(w -> pos.row, w -> pos.col);
  212.         free(w);
  213.         }
  214. }
  215.